﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MG.HomeO2O.Model;
using System.Data;
namespace MG.HomeO2O.DAL
{
    public class member_listDAL
    {
        EntityOP entity = new EntityOP();
        /// <summary>
        /// 人员显示
        /// </summary>
        /// <returns></returns>
        public List<personnel> pershow()
        {
            return entity.personnel.SqlQuery("select p.Pid,p.Pname,p.PimgPath,p.Patate,p.Page,p.Parea,p.Lengthage,p.Sketch,p.Remark,f.FName,f.FID,p.Patate from personnels p left join Features f on p.FID =f.FID").ToList();
        }
        /// <summary>
        /// 人员添加
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public bool peradd(personnel p)
        {
            entity.personnel.Add(p);
            return entity.SaveChanges() > 0;
        }
        /// <summary>
        /// 人员删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool perdelete(int id)
        {
            personnel p = entity.personnel.Find(id);
            entity.personnel.Remove(p);
            return entity.SaveChanges() > 0;
        }
        /// <summary>
        /// 获取人员编号
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public personnel getperid(int id)
        {
            return entity.personnel.Find(id);
        }
        /// <summary>
        /// 人员修改
        /// </summary>
        /// <param name="p"></param>
        /// <returns></returns>
        public bool perupdate(personnel p)
        {
            entity.Entry(p).State = System.Data.EntityState.Modified;
            return entity.SaveChanges() > 0;
        }
    }
}
